package com.plugin.storage.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AuthToken {

    @JsonProperty("AccessKeyId")
    private String accessKeyId;

    @JsonProperty("AccessKeySecret")
    private String accessKeySecret;

    @JsonProperty("SecurityToken")
    private String securityToken;

    @JsonProperty("Expiration")
    private long expiration;

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public AuthToken setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
        return this;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public AuthToken setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
        return this;
    }

    public String getSecurityToken() {
        return securityToken;
    }

    public AuthToken setSecurityToken(String securityToken) {
        this.securityToken = securityToken;
        return this;
    }

    public long getExpiration() {
        return expiration;
    }

    public AuthToken setExpiration(long expiration) {
        this.expiration = expiration;
        return this;
    }

    @JsonIgnore
    public int getTTL() {
        return (int) (getExpiration() - System.currentTimeMillis()) / 1000 - 1;
    }

    @Override
    public String toString() {
        return "AuthToken{" +
                "accessKeyId='" + accessKeyId + '\'' +
                ", accessKeySecret='" + accessKeySecret + '\'' +
                ", securityToken='" + securityToken + '\'' +
                ", expiration=" + expiration +
                '}';
    }
}
